Imports System.Data.SqlClient

Friend Class DBLogin
    Inherits DBBase

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub Load(ByRef oObject As SQLAutoDocLib.Login)

        Dim sSQL As String = "select"
        sSQL = sSQL & "     [Login],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [DatabaseRevID],"
        sSQL = sSQL & "     [IsNTUser],"

        sSQL = sSQL & "     [IsDeleted],"
        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]"
        sSQL = sSQL & " from"
        sSQL = sSQL & "     tDDLogins"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        Dim oData As DataTable = MyBase.ExecuteReadToDataTable(sSQL)

        With oObject
            .Login = oData.Rows(0).Item("Login")
            .Desc = NullToString(oData.Rows(0).Item("Desc"))
            .DatabaseID = oData.Rows(0).Item("DatabaseID")
            .DatabaseRevID = oData.Rows(0).Item("DatabaseRevID")
            .UseIntegratedSecurity = oData.Rows(0).Item("IsNTUser")

            .IsDeleted = oData.Rows(0).Item("IsDeleted")
            .CreateName = oData.Rows(0).Item("CreateName")
            .CreateDate = oData.Rows(0).Item("CreateDate")
            .ChangeName = NullToString(oData.Rows(0).Item("ChangeName"))
            .ChangeDate = NullToString(oData.Rows(0).Item("ChangeDate"))
        End With

        oData.Dispose()
    End Sub

    Public Sub Update(ByRef oObject As SQLAutoDocLib.Login)
        Dim sSQL As String = "update tDDLogins set"
        sSQL = sSQL & "     [Login]=" & ValueToDBValue(oObject.Login) & ","
        sSQL = sSQL & "     [Desc]=" & ValueToDBValue(oObject.Desc) & ","
        sSQL = sSQL & "     [DatabaseID]=" & ValueToDBValue(oObject.DatabaseID) & ","
        sSQL = sSQL & "     [DatabaseRevID]=" & ValueToDBValue(oObject.DatabaseRevID) & ","
        sSQL = sSQL & "     [IsNTUser]=" & BooleanToBit(oObject.UseIntegratedSecurity) & ","

        sSQL = sSQL & "     [IsDeleted]=" & BooleanToBit(oObject.IsDeleted) & ","
        sSQL = sSQL & "     [CreateName]=" & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & "     [CreateDate]=" & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & "     [ChangeName]=" & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & "     [ChangeDate]=" & ValueToDBValue(oObject.ChangeDate)
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Add(ByRef oObject As SQLAutoDocLib.Login)
        Dim oNextID As New DBNextIDValue("Login")
        Dim lNextID As Long = oNextID.NextValue
        oObject.ID = lNextID

        Dim sSQL As String = "insert into tDDLogins ("
        sSQL = sSQL & "     [ID],"
        sSQL = sSQL & "     [Login],"
        sSQL = sSQL & "     [Desc],"
        sSQL = sSQL & "     [DatabaseID],"
        sSQL = sSQL & "     [DatabaseRevID],"
        sSQL = sSQL & "     [IsNTUser],"

        sSQL = sSQL & "     [IsDeleted],"
        sSQL = sSQL & "     [CreateName],"
        sSQL = sSQL & "     [CreateDate],"
        sSQL = sSQL & "     [ChangeName],"
        sSQL = sSQL & "     [ChangeDate]) values ("

        sSQL = sSQL & ValueToDBValue(oObject.ID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Login) & ","
        sSQL = sSQL & ValueToDBValue(oObject.Desc) & ","
        sSQL = sSQL & ValueToDBValue(oObject.DatabaseID) & ","
        sSQL = sSQL & ValueToDBValue(oObject.DatabaseRevID) & ","
        sSQL = sSQL & BooleanToBit(oObject.UseIntegratedSecurity) & ","

        sSQL = sSQL & BooleanToBit(oObject.IsDeleted) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.CreateDate) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeName) & ","
        sSQL = sSQL & ValueToDBValue(oObject.ChangeDate) & ")"

        MyBase.ExecuteNonQuery(sSQL)
    End Sub

    Public Sub Delete(ByRef oObject As SQLAutoDocLib.Login)
        Dim sSQL As String = "delete from tDDLogins"
        sSQL = sSQL & " where"
        sSQL = sSQL & "     [ID]=" & oObject.ID

        MyBase.ExecuteNonQuery(sSQL)
    End Sub
End Class
